<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\ExcelExpoter;
use App\Models\log;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class LogController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('Log Operation');
            $content->description('...');
            $content->body($this->grid());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(log::class, function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->exporter(new ExcelExpoter());
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableEdit();
            });
            $grid->filter(function($filter){
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                // 在这里添加字段过滤器
                $filter->like('name', 'name');
            });
            $grid->id('ID')->sortable();
            $grid->user_name('用户');
            $grid->opration('操作')->label('info');
            $grid->time('时间');
        });
    }
    protected function form()
    {
        return Admin::form(Log::class, function (Form $form) {
            $form->hidden('id', 'ID');
        });
    }
}
